package com.mianyang.zhangsan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mianyang.zhangsan.common.base.BaseController;
import com.mianyang.zhangsan.common.base.R;
import com.mianyang.zhangsan.model.dto.SecPaperCorrectDto;
import com.mianyang.zhangsan.model.dto.SecPaperDto;
import com.mianyang.zhangsan.model.entity.SecPaper;
import com.mianyang.zhangsan.service.SecPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiangjr
 * @date 2022-11-30
 */
@RestController
@RequestMapping("/paper")
public class SecPaperController extends BaseController {
    @Autowired
    private SecPaperService paperService;

//    /**
//     * 导出试卷
//     */
//    @PostMapping("/generator/{paperId}")
//    public R exportPaper(@PathVariable("paperId") Long paperId) {
//        String paperPath = paperService.exportPaper(paperId);
//        return success("url", paperPath);
//    }

    /**
     * 生成试卷
     */
    @PostMapping("/generator")
    public R generatorPaper(@RequestParam(value = "templateId") Long templateId,
                            @RequestParam(value = "bankId") Long bankId,
                            @RequestParam(value = "paperName") String paperName,
                            @RequestParam(value = "paperDesc", required = false) String paperDesc) {
        SecPaper paper = paperService.generatorPaper(templateId, paperName, paperDesc, bankId);
        return success("paper", paper);
    }

    /**
     * 查询试卷
     */
    @GetMapping("/query")
    public R queryPaper(SecPaper paper,
                        @RequestParam(value = "current", defaultValue = "1") int current,
                        @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        Page<SecPaper> papers = paperService.selectPaperByPage(paper, current, pageSize);
        return success("papers", papers);
    }

    /**
     * 修改试卷
     */
    @PutMapping("/edit")
    public R editPaper(@RequestBody SecPaper paper) {
        paperService.updateById(paper);
        return success();
    }
}
